<?xml version="1.0" encoding="UTF-8"?>
<!-- Please don't edit this document if you are not familiar with
     Ant and XML.
 -->
<project name="SD Web Api" default="build-all">

    <target name="help" depends="config">
        <echo>
        Service Desk Web API build.xml help
        
        usage: ANT &lt;target&gt;
        target:
            o [clean ]      : delete all files generated when run web api build task            
            o [config]      : initiate the target properties                                  
            o [build-webapi]: build web api  
            o [webapidoc]   : build web api javadocs 
            o [build-all]   : build all the targets 
            o [rebuild]     : rebuild all targets
            
        Before building web api, user must configure the properties defined in 
        build.properties, which can be found in the same directory of this 
        build file.  Those properties are:               
            sd_webapi_output_dir: Web API source output directory     
            sd_official_webapi  : The official web api jar file 
            sd_official_webapi_javadoc: The official web api javadoc file   
            
        After target [build-all] is successfully run, new web api
        jar file and web api javadoc file can be found in ${sd_webapi_output_dir}. 
            
        </echo>
    </target>
    
    <target name="config">
        <property file="build.properties"/>    
        <property name="webapi-jar" value="${sd_webapi_output_dir}/web-api.jar"/>  
        <property name="webapi-src" value="${sd_webapi_output_dir}/web-api/api-client/src"/>  
        <property name="webapi-classes" value="${sd_webapi_output_dir}/web-api/api-client/classes"/>
        <property name="webapi-full" value="${sd_webapi_output_dir}/web-api/api-full"/>
        <property name="webapi-full-classes" value="${webapi-full}/classes"/>
        <property name="webapi-depend-jar" value="${sd_webapi_output_dir}/api-depend.jar"/>
        
        <property name="wad_header" value="Service Desk 4.5 Web Api" />
		<property name="wad_tempdir" location="${sd_webapi_output_dir}/temp/webapi" />
		<property name="wad_dest" location="${sd_webapi_output_dir}/webapi-javadocs" />
		<property name="wad_log" value="${sd_webapi_output_dir}/webapidoc.log" />
		<property name="wad_zip" value="${sd_webapi_output_dir}/web_api_javadoc.zip" />
    </target>
    
    <target name="build-webapi" depends="config" >  
        <mkdir dir="${webapi-full-classes}" />
        <unjar src="${sd_official_webapi}" dest="${webapi-full-classes}" overwrite="true"/>  
        <delete>
          <fileset dir="${webapi-full-classes}/com/hp/itsm/api/" excludes="**/examples/*"/>        
        </delete>    
        <jar basedir="${webapi-full-classes}" jarfile="${webapi-depend-jar}"/>  
        <mkdir dir="${webapi-classes}" />  
        <javac 
            destdir="${webapi-classes}"
            srcdir="${webapi-src}" 
            includeantruntime="no"
            verbose="no"
            fork="yes"
            memoryInitialSize="128m"
            memoryMaximumSize="256m"
            failonerror="yes" >
            <classpath>
                <pathelement location="${webapi-depend-jar}" />             
            </classpath>
        </javac>  
        
        <delete file="${webapi-depend-jar}"/>    
        
        <copy todir ="${webapi-full-classes}" overwrite="true">
            <fileset dir="${webapi-classes}">
            </fileset>
        </copy>        
        <jar basedir="${webapi-full-classes}" jarfile="${webapi-jar}" />        
    </target>

    <!-- Generate webapi javadoc -->
	<target name="webapidoc" depends="build-webapi">
		<echo>
         The logfile is stored at ${wad_log}
        </echo>
		<delete dir="${wad_tempdir}" />
		<mkdir dir="${wad_tempdir}" />
		<!-- copy desired source file to a temp directory -->
		<copy todir="${wad_tempdir}">
			<fileset dir="${webapi-src}">
				<include name="**/IApi*.java" />
				<include name="**/interfaces/I*.java" />
				<include name="com/hp/itsm/api/ApiSDSession.java" />
				<include name="com/hp/itsm/api/ApiEntityMap.java" />				
			</fileset>
		</copy>
		<!-- prepare the destination directory -->
		<delete dir="${wad_dest}" />
		<mkdir dir="${wad_dest}" />
		<mkdir dir="${wad_dest}/html" />
		<unzip src="${sd_official_webapi_javadoc}" dest="${wad_dest}/official" />
		<delete>		  
		    <fileset dir="${wad_dest}/official/com/hp/itsm/api/" excludes="**/examples/*"/> 
		</delete>
		<javadoc maxmemory="400M" destdir="${wad_dest}/html" classpath="${webapi-jar}" private="true" use="false" splitindex="true" windowtitle="${wad_header}" doctitle="${wad_header}" packagenames="com.hp.*" sourcepath="${wad_tempdir}">
		</javadoc>	
       
       	<copy todir="${wad_dest}/official/com/hp/itsm/api" overwrite="true">
			<fileset dir="${wad_dest}/html/com/hp/itsm/api/"/>
		</copy>
		
		<zip basedir="${wad_dest}/official" destfile="${wad_zip}" compress="true"/>
		<!-- clean up -->
		<delete dir="${wad_tempdir}" />
		<echo>
         The logfile is stored at ${wad_log}
        </echo>
	</target>

    <target name="clean" depends="config"> 
       <delete file="${webapi-jar}"/>
       <delete file="${wad_zip}"/>
       <delete dir="${webapi-classes}"/> 
       <delete dir="${webapi-full}"/> 
       <delete dir="${wad_dest}"/> 
       <delete dir="${sd_webapi_output_dir}/temp"/>
    </target>
    
    <target name="rebuild" depends="clean, build-all">
	</target>
	
	<target name="build-all" depends="config, build-webapi, webapidoc">
	</target>
</project>